package com.netty.pro.netty.nio;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.channels.FileChannel;

/**
 * @author xuzn
 * @ClassName: NioCopyByTransferFrom
 * @ProjectName echo-project
 * @date 2020/3/5/11:22
 */
public class NioCopyByTransferFrom {

  public static void main(String[] args) throws Exception {
    // 创建输入输出流
    FileInputStream fileInputStream = new FileInputStream("1.txt");
    FileOutputStream fileOutputStream = new FileOutputStream("3.txt");
    // 获取各个流的channel
    FileChannel sourceCh = fileInputStream.getChannel();
    FileChannel destCh = fileOutputStream.getChannel();
    destCh.transferFrom(sourceCh, 0, sourceCh.size());
    sourceCh.close();
    destCh.close();
    fileInputStream.close();
    fileOutputStream.close();
  }
}
